package com.example.mapper;

import com.example.entity.ShoppingCar;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface ShoppingCarMapper {

 /**
  * 动态查询
  * @param shoppingCar
  * @return
  */

 List<ShoppingCar> shoppingCar(ShoppingCar shoppingCar);


 /**
  * 根据ID修改商品数量
  * @param shoppingCar
  */
 @Update("update shopping_cart set number=#{number} where id=#{id}")
 void updateNumberById(ShoppingCar shoppingCar);


 /**
  * 添加购物车数据
  * @param shoppingCar
  */
 @Insert("insert into shopping_cart (name, image, user_id,setmeal_id, number, amount, create_time) " +
         "values (#{name},#{image},#{userId},#{setmealId},#{number},#{amount},#{createTime})")
 void insert(ShoppingCar shoppingCar);


 /**
  * 查看购物车
  */
 @Select("select * from shopping_cart ")
 List<ShoppingCar> getShoppingCar(ShoppingCar shoppingCar);


 /**
  * 清空购物车
  * @param userId
  */
 @Delete("delete from shopping_cart where user_id=#{userId}")
 void cleanShoppingCar(Long userId);

 /**
  * 根据id删除购物车数据
  * @param id
  */
 @Delete("delete from shopping_cart where id = #{id}")
 void deleteById(Long id);

}
